from selenium import webdriver   # 在selenium中引用
from selenium.webdriver.common.by import By
from time import sleep
from options import options
# from test_cases_webtours import service
url = r'http://172.16.36.121/upload/'
driver = webdriver.Chrome(options=options)
driver.get(url)
driver.maximize_window()    # 访问页面扩大
# 登录
driver.find_element(By.ID,'ls_username').clear()
driver.find_element(By.ID,'ls_username').send_keys('test')
driver.find_element(By.ID,'ls_password').clear()
driver.find_element(By.ID,'ls_password').send_keys('123')
sleep(3)
driver.find_element(By.XPATH,'//*[@id="lsform"]/div/div/table/tbody/tr[2]/td[3]/button/em').click()
sleep(3)
# # 发帖
# driver.find_element(By.XPATH,'//*[@id="category_1"]/table/tbody/tr[1]/td[2]/h2/a').click()
# driver.find_element(By.XPATH,'//*[@id="newspecial"]/img').click()
# driver.find_element(By.ID,'subject').send_keys('今天天气真好')
#
# driver.switch_to.frame('e_iframe')    # 跳转到嵌套里面
# driver.find_element(By.XPATH, '/html/body').clear()
# driver.find_element(By.XPATH, '/html/body').send_keys('今天有点冷啊')
# driver.switch_to.default_content()    # 跳出嵌套
# driver.find_element(By.ID,'postsubmit').click()
# sleep(3)

# 注册
# driver.find_element(By.XPATH,'//*[@id="lsform"]/div/div/table/tbody/tr[2]/td[4]/a').click()
# driver.find_element(By.ID,'qR1Zf7').send_keys('test3')
# driver.find_element(By.ID,'Dguu11').send_keys('123456')
# driver.find_element(By.ID,'Fzes72').send_keys('123456')
# driver.find_element(By.ID,'i43045').send_keys('test4@qq.com')
# driver.find_element(By.XPATH,'//*[@id="registerformsubmit"]/strong').click()
# sleep(6)
# 查看帖子
driver.find_element(By.XPATH,'//*[@id="category_1"]/table/tbody/tr[1]/td[2]/h2/a').click()
driver.find_element(By.XPATH,'//*[@id="normalthread_4"]/tr/th/a[2]').click()
sleep(3)
# 回复帖子
# //*[@id="post_replytmp"]/img
driver.find_element(By.XPATH,'//*[@id="post_replytmp"]/img').click()
sleep(2)
driver.find_element(By.XPATH,'//*[@id="postmessage"]').send_keys('今天天气就是好')
driver.find_element(By.XPATH,'//*[@id="postsubmit"]/span').click()
sleep(3)
# 退出
driver.find_element(By.LINK_TEXT,'退出').click()
sleep(3)
driver.quit()